﻿using System;
using System.Collections.Generic;
using System.Text;
using net.veekee.common;
using System.Reflection;
using System.Text.RegularExpressions;

namespace net.veekee.common.data
{
    [Serializable]
    public class FieldManager : CollectionManager<String>
    {
        public override void Set<T>(String name, T value)
        {
            name = name.ToLower();
            base.Set<T>(name, value);
        }

        public override T Get<T>(String name, T defaultValue)
        {
            name = name.ToLower();
            return base.Get<T>(name, defaultValue);
        }

        public virtual void Load(String inlineValues)
        {
            if (inlineValues == null)
                return;
            Regex ex = new Regex(@"(?<Header>[^<>;]*)<(?<Field>[^<>;]*)>");
            try
            {
                MatchCollection matches = ex.Matches(inlineValues);
                foreach (Match m in matches)
                {
                    this.Set(m.Groups["Header"].Value, m.Groups["Field"].Value);
                }
            }
            catch (Exception e)
            {
                Log.GetInstance().Error(e.ToString());
            }
        }

    }
}
